<?php
class User extends AppModel {

	var $name = 'User';

	var $validate = array(
		'username' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
			'maxLength' => array(
				'rule'    => array('maxLength', '16'),
				'message' => 'Username cannot be longer than 16 characters'
			),
			'isUnique' => array(
				'rule'    => 'isUnique',
				'message' => 'Username is alreay taken'
			)
		),

		'password' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
			'maxLength' => array(
				'rule'    => array('maxLength', '40'),
				'message' => 'Password cannot be longer than 40 characters'
			)
		),

		'confirm_password' => array(
			'confirmPassword' => array(
				'rule'    => array('confirmPassword'),
				'message' => 'Passwords do not match'
			)
		),

		'first_name' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
			'maxLength' => array(
				'rule'    => array('maxLength', '32'),
				'message' => 'First name cannot be longer than 32 characters'
			)
		),

		'last_name' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
		),

		'email' => array(
			'email' => array(
				'rule' => 'email',
				'message' => 'Invalid email address'
			)
		),

		'secret_question_id' => array('notempty'),

		'secret_question_answer' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
			'maxLength' => array(
				'rule'    => array('maxLength', '1024'),
				'message' => 'Answer cannot be longer than 1024 characters'
			)
		),

		'primary_phone' => array(
			'phone' => array(
				'rule'       => 'phone',
				'message'    => 'Invalid phone number',
				'allowEmpty' => true
			)
		),

		'secondary_phone' => array(
			'phone' => array(
				'rule'       => 'phone',
				'message'    => 'Invalid phone number',
				'allowEmpty' => true
			)
		),

		'street_address_1' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
			'maxLength' => array(
				'rule'    => array('maxLength', '64'),
				'message' => 'Address cannot be longer than 64 characters'
			)
		),

		'street_address_2' => array(
			'maxLength' => array(
				'rule'    => array('maxLength', '64'),
				'message' => 'Address cannot be longer than 64 characters'
			)
		),

		'city' => array(
			'notEmpty' => array(
				'rule'    => 'notEmpty',
				'message' => 'This field cannot be left blank'
			),
			'maxLength' => array(
				'rule'    => array('maxLength', '64'),
				'message' => 'City cannot be longer than 64 characters'
			)
		),

		'postal_code' => array(
			'rule'    => array('postal', null, 'ca'),
			'message' => 'Invalid postal code'
		),

		'active' => array(
			'rule' => '/^[01]$/',
			'message' => 'Invalid value for field',
			'required' => false
		)
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed
	var $belongsTo = array(
		'SecretQuestion' => array(
			'className'  => 'SecretQuestion',
			'foreignKey' => 'secret_question_id',
			'conditions' => '',
			'fields'     => '',
			'order'      => ''
		),
		'Role' => array(
			'className'  => 'Role',
			'foreignKey' => 'role_id',
			'conditions' => '',
			'fields'     => '',
			'order'      => ''
		)
	);

	function confirmPassword() {
		App::import('Component', 'Auth');
		return $this->data['User']['password'] == AuthComponent::password($this->data['User']['confirm_password']);
	}
}
?>